//
//  MainViewController.swift
//  LiveShow
//
//  Created by dai zhong on 2017/4/25.
//  Copyright © 2017年 company.cn. All rights reserved.
//

import UIKit
import Foundation

class MainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        setupUI();
    }
    
    override func viewWillAppear(_ animated: Bool) {
        print("viewWillAppear----")
    }

}

extension MainTabBarController{

    fileprivate func barButtonItemDidClicked(){
    
    }
}

extension MainTabBarController{

    fileprivate func setupUI(){
    
        self.addChildControllers();
    }
    
    fileprivate func addChildControllers(){
    
        self.addChildVc("Live")
        self.addChildVc("Rank")
        self.addChildVc("Discover")
        self.addChildVc("Profile")
    }
    
    fileprivate func addChildVc(_ controllerName:String){
        
        let nameSpace = Bundle.main.infoDictionary?["CFBundleExecutable"] as! String;
        let controller :AnyClass = NSClassFromString(nameSpace + "." + controllerName + "ViewController")!;
        let viewController = (controller as! UIViewController.Type).init();
        
        let normalImg = UIImage(named: controllerName.lowercased() + "_normal");
        let selectedImg = UIImage(named: controllerName.lowercased() + "_selected");

        viewController.tabBarItem.image = normalImg;
        viewController.tabBarItem.selectedImage = selectedImg;
        
        let mainNavVC = MainNavigationController(rootViewController: viewController);
        self.addChildViewController(mainNavVC);
    }
}
























